package main

import (
	"log"
	"net/http"
	"github.com/zhulizhe/golang-shortlink/internal/handler"
	"github.com/zhulizhe/golang-shortlink/internal/repository"
	"github.com/zhulizhe/golang-shortlink/internal/service"
)

func main() {
	repo := repository.NewMemoryLinkRepository()
	service := service.NewLinkService(repo)
	h := handler.NewHandler(service)

	http.HandleFunc("/api/shorten", h.CreateShortLink)
	http.HandleFunc("/api/stats", h.Stats)
	// 兜底路由做短链重定向
	http.HandleFunc("/", h.Redirect)

	log.Println("服务启动于 :8080 ...")
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal(err)
	}
}
